package com.example.project_springboot.controller;

import com.example.project_springboot.aop.Log;
import com.example.project_springboot.pojo.Emp;
import com.example.project_springboot.pojo.PageBean;
import com.example.project_springboot.pojo.Result;
import com.example.project_springboot.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * 员工管理Controller
 */

@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    EmpService empService;

    @GetMapping
    public Result selectEmp(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                            String name, Short gender, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageBean result = empService.selectEmp(page, pageSize, name, gender, begin, end);
        return Result.success(result);
    }

    @DeleteMapping("/{ids}")
    @Log
    public Result deleteEmp(@PathVariable Long[] ids) {
        empService.deleteEmp(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Emp emp = empService.getById(id);
        return Result.success(emp);
    }

    @PutMapping
    @Log
    public Result update(@RequestBody Emp emp){
//        int a = 1/0;
        empService.update(emp);
        return Result.success();
    }


}
